/**
 * 
 */
package belote.webapp.tag;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

/**
 * @author Gwenn
 *
 */
@SuppressWarnings("serial")
public class EnvironnementTag extends TagSupport {

	/**
	 * {@inheritDoc}}
	 */
	@Override
	public int doStartTag() throws JspException {
		
		HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
		
		// APPLICATION_ROOT_PATH
		StringBuilder sbARP = new StringBuilder();
		sbARP.append(request.getScheme()).append("://").append(request.getServerName());
		if (request.getServerPort() != 80) {
			sbARP.append(":").append(request.getServerPort());
		}
		sbARP.append(request.getContextPath());
		request.setAttribute("APPLICATION_ROOT_PATH", sbARP.toString());
		
		// STATIC_ROOT_PATH
		StringBuilder sbSRP = new StringBuilder();
		sbSRP.append(sbARP).append("/static");
		request.setAttribute("STATIC_ROOT_PATH", sbSRP.toString());
				
		return super.doStartTag();
	}
}
